package com.beidouapp.mq.service;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Autowired;

import com.wisesoft.mq.EventControlConfig;
import com.wisesoft.mq.TopicInfo;
import com.wisesoft.mq.impl.TopicEventController;

public class IMConsumerTopicService {
	    @Autowired
	    private EventControlConfig eventControlConfig;
	 
	    private List<TopicInfo> topicList;
	    
	    TopicEventController controller;

	    @PostConstruct
	    public void init()
	    {
	       
	        controller = TopicEventController.getInstance(eventControlConfig);

	        for (TopicInfo topicInfo: topicList)
	        {
	            controller.add(eventControlConfig.getUsername(),topicInfo.getExchange(),topicInfo.getTopic(), topicInfo.getEventProcesser());
	        }
	        controller.start();
	    }
	    @PreDestroy
	    public void  dostory(){
	    	if(controller!=null){
	      	  try {
	  			controller.destroy();
	  		} catch (Exception e) {
	  			e.printStackTrace();
	  		}
	      	}
	    }

	    public List<TopicInfo> getTopicList() {
	        return topicList;
	    }

	    public void setTopicList(List<TopicInfo> topicList) {
	        this.topicList = topicList;
	    }
}
